const addZero = item => {
  item = item < 10 ? '0' + item : item;
  return item;
};

/* 时间戳转换成"yyyy-mm-dd hh:mm:ss"格式 */
const getTime = (newTime = new Date(), type = 'long') => {
  // let newTime = new Date();
  let Year = newTime.getFullYear();
  let Month = addZero(newTime.getMonth() + 1);
  let Day = addZero(newTime.getDate());
  let Hour = addZero(newTime.getHours());
  let Minute = addZero(newTime.getMinutes());
  let Second = addZero(newTime.getSeconds());
  if (type === 'long') {
    return `${Year}-${Month}-${Day} ${Hour}:${Minute}:${Second}`;
  }
  if (type === 'short') {
    return `${Year}-${Month}-${Day}`;
  }

  return `${Hour}:${Minute}:${Second}`;


};
const getTimeString = (newTime = new Date()) => {
  // let newTime = new Date();
  let Year = newTime.getFullYear();
  let Month = addZero(newTime.getMonth() + 1);
  let Day = addZero(newTime.getDate());

  return `${Year}${Month}${Day}`;


};


const debounce = (fn, delay) => {
  let timeoutID = null;
  return function later(...args) {
    clearTimeout(timeoutID);
    let that = this;
    timeoutID = setTimeout(() => {
      fn.apply(that, args);
    }, delay);
  };
};

const regRule = {
  idCard:/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,
  phone:'',
};

export default {
  addZero,
  getTime,
  getTimeString,
  debounce,
  regRule
};
